<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/style.css">
    <title>店铺名称</title>
</head>
{include file="public/href" /}
<body>
<div class="wrap-rew">
    <div class="header">
        <p>评价管理</p>
        <img src="__STATIC__/img/back.png" class="back" onclick =window.location.href="{:url('mobile/shop_auth/member_shop')}";>
        <!--<span><a href="{:url('mobile/shop_auth/history_reply')}">历史回复</a></span>-->
    </div>
    <div class="center">

    </div>
    <div class="footer" style="display: none;">
        <input type="search" id="reply_content" placeholder="写评论"><label onclick="send()">发送</label>
        <img src="__STATIC__/img/write.png">
        <input type="hidden" value="" id="now" />
    </div>

</div>
{include file="public/src" /}
<script>
    //layer流加载
    layui.use('flow', function() {
        var $ = layui.jquery;
        var flow = layui.flow;
        var show = $('#show').val(); //当前浏览的类型
        var sort_type = $('#sort_type').val(); //当前排序的类型
        var search = $('#search').val();
        flow.load({
            elem: '.center' //流加载容器
            ,isAuto:true
            ,isLazyimg:true
            ,done: function(page, next){ //执行下一页的回调
                var lis = [];
                $.ajax({
                    url:"{:url('mobile/shop_auth/evaluate_manage')}",
                    dataType:'json',
                    type:'post',
                    data:{'page':page},
                    success:function(t){
                        layui.each(t.data, function(index, item){
                            var nickname = "未设置";
                            var avatar = "/static/mobile/img/empty_img.png";
                            if (item.nickname){
                                nickname = item.nickname;
                            }
                            if (item.avatar){
                                if (item.avatar.indexOf('http')){  //微信头像
                                    avatar = item.avatar;
                                }else{
                                    avatar = '/'+item.avatar;
                                }
                            }
                            //几颗星
                            var star = '';
                            if (item.grade){   //有评分
                                for (var i=0;i<item.grade;i++){
                                    star += '<img src="__STATIC__/img/star.png">' ;
                                }
                            }
                            var attr = '无属性';
                            if (item.attr){
                                attr = item.attr;
                            }
                            var reply = '<span onclick="reply('+item.id+')"> 回复</span>';
                            var content = '';
                            if (item.reply_status == 1){
                                reply = '<span onclick="see_reply('+item.id+')">已回复</span>';
                                content = '<div style="display: none" id="content_'+item.id+'" >'+item.reply+'</div>';
                            }
                            var extra = '';
                            if (item.picArr){ //带图的评价
                                for (var i=0;i<item.picArr.length;i++){
                                    extra += '<li style="width: 33.3%;float: left;text-align: center;"><img src="/'+item.picArr[i]+'" onerror=this.src="/static/mobile/img/empty_img.png" width="80" height="80"></a></li>';
                                }
                            }
                            lis.push('<div class="review">' +
                                    '<div class="title"><img src="'+avatar+'">' +
                                    '<p>'+nickname+'</p>' +
                                    '<div class="star">' +
                                    star+
                                    '</div>' +
                                    '</div>' +
                                    '<p>'+item.content+'</p>' +
                                    '<div class="reply">' +
                                    '<span>'+item.create_time+' 规格属性：'+attr+'</span>' +
                                    '<p id="reply_'+item.id+'" ><img style="margin-top: 13%;" src="__STATIC__/img/review.png">&nbsp;'+reply+'</p>' +
                                    content+
                                    '</div>' +
                                    '<ul style="width: 100%;overflow: hidden;padding-top: 2%;">'+extra+'</ul></div>');
                        });
                        next(lis.join(''), page < t.pages);
                    },
                    error:function () {
                        layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
                    }
                })
            }
        });
    });
    //回复评论
    function reply(id){
        $('.footer').toggle();
        $('#now').val(id);
    }
    //发送评论
    function send(){
        var id = $('#now').val();
        var content = $('#reply_content').val();
        if (content == ''){
            layer.open({content:'评论内容不能为空',skin:'msg',time:2});
        }else{
            $.ajax({
                url:"{:url('mobile/shop_auth/reply_content')}",
                data:{'content':content,'id':id},
                type:'post',
                dataType:'json',
                success:function (data) {
                    layer.open({content:data.message,skin:'msg',time:2});
                    if (data.code == 200){
                        $('#reply_'+id).html('<img style="margin-top: 13%;" src="__STATIC__/img/review.png">&nbsp;<span onclick="see_reply('+id+')" >已回复</span>');
                        $('<div style="display: none" id="content_'+id+'" >'+content+'</div>').insertAfter($('#reply_'+id));
                        $('.footer').toggle();
                    }
                },
                error:function () {
                    layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
                }
            })
        }
    }
    //查看回复内容
    function see_reply(id){
        $('#content_'+id).toggle();
    }
</script>
</body>
</html>